import {onEnter, isWeiXin, isAndroid, setupWebViewJavascriptBridge, setItem} from '../../utils';
import Cookies from 'js-cookie';

module.exports = {
    path: 'actMan',
    onEnter: isWeiXin() ? onEnter : () => {
        if (isAndroid()) {
            let token = Cookies.get('accesstoken');
            if (token) {
                setItem('token', token);
            } else {
                alert('用户未登录')
            }
        } else {
            setupWebViewJavascriptBridge(function (bridge) {
                if (isAndroid()) {
                    if (window.WVJBCallbacks) { //注册默认接收android回调函数,ios不能加
                        bridge.init(function (message, responseCallback) {
                            var data = {'Javascript Responds': 'Wee!'};
                            responseCallback(data);
                        })
                    }
                }
                bridge.registerHandler("accessTokenCallBack", function (data, responseCallback) {
                    let token = data.accesstoken;
                    if (token) {
                        setItem('token', token);
                    } else {
                        alert('用户未登录')
                    }
                })
            });
        }
    },
    getComponent(location, cb) {
        require.ensure([], (require) => {
            cb(null, require('../../containers/userCenter/actMan').default);
        });
    }
};
